<script type="text/javascript" src="/js/plugins/ckeditor/ckeditor.js"></script>
<link type="text/css" rel="stylesheet" href="/js/plugins/uploadifive/uploadifive.css" />
<script type="text/javascript" src="/js/plugins/uploadifive/jquery.uploadifive.min.js"></script>
<div class="container-fluid cm-container-white">
	<div class="panel panel-default">
		<form action="/articles" method="post" id="articleSaveForm">
			<input name="id" type="hidden" value="${article.id}"/>
			<input name="articleContent.id" type="hidden" value="${articleContent.id}"/>
			<input name="articleContent.articleId" type="hidden" value="${articleContent.articleId}"/>
			<input name="userName" type="hidden" value="${article.userName}"/>
			<input name="count" type="hidden" value="${article.count}"/>
			<input name="count" type="hidden" value="${article.count}"/>
			<div class="panel-body">
				<table class="table table-bordered">
					<thead>
						<tr class="active">
							<th colspan="6" style="text-align: center;">文章基本信息</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<th>文章标题</th>
							<td><input class="form-control" name="title" value="${article.title }"></td>
							<th>文章编码</th>
							<td><input class="form-control" name="code" value="${article.code }"></td>
							<td rowspan="4">
								<div class="image-div">
									<div style="font-weight: bold; font-size: 10">文章封面</div>
									<img
										style="width: 120px; height: 100px; margin-top: 5px; margin-bottom: 5px;" src="${article.imgPath}">
									<div>
										<a href="javascript:;" id="butn">上传</a>
									</div>
									<input type="hidden" name="imgPath" id="imgPath" value="${article.imgPath}">
								</div>
							</td>
						</tr>
						<tr>
							<th>文章类型</th>
							<td><select class="form-control" name="articleType">
									<#list articleTypeList as articleType>
										<#if article.articleTypeVo.code == articleType.code>
											<option value="${articleType.code}" selected="selected">${articleType.name}</option>
										<#else>
											<option value="${articleType.code}">${articleType.name}</option>
										</#if>
									</#list> 
							</select></td>
							<th>是否发布</th>
							<td><select class="form-control" name="publish">
									<#if article.publish == 1>
											<option value="1" selected="selected">是</option>
											<option value="0">否</option>
										<#else>
											<option value="1">是</option>
											<option value="0" selected="selected">否</option>
										</#if>
									
							</select></td>
						</tr>
						
						<tr>
							<th>是否推荐</th>
							<td><select class="form-control" name="praise">
									<#if article.praise == 1>
											<option value="1" selected="selected">是</option>
											<option value="0">否</option>
										<#else>
											<option value="1">是</option>
											<option value="0" selected="selected">否</option>
										</#if>
							</select></td>
							<th>是否热门</th>
							<td><select class="form-control" name="hot">
									<#if article.hot == 1>
											<option value="1" selected="selected">是</option>
											<option value="0">否</option>
										<#else>
											<option value="1">是</option>
											<option value="0" selected="selected">否</option>
										</#if>
							</select></td>
						</tr>
						<tr>
							<th>关键字</th>
							<td><input class="form-control" name="keyword" value="${article.keyword }"></td>
							<th>排序号</th>
							<td><input class="form-control" name="sort" value="${article.sort }"></td>
						</tr>
					</tbody>
				</table>

				<table class="table table-bordered">
					<thead>
						<tr class="active">
							<th style="text-align: center;">文章详细内容</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<th>
								<div class="row">
									<div class="col-lg-12">
										<div class="form-group">
											<textarea id="articleContent" name="articleContent.content"
												class="ckeditor" rows="10"></textarea>
										</div>
									</div>
								</div>
							</th>
						</tr>
					</tbody>
				</table>
			</div>
			<div class="modal-footer">
                 <button type="button" class="btn btn-primary" id="saveButton">保存</button>
             </div>
		</form>
	</div>
</div>
<script type="application/javascript">
$(function () {

    var ckeditor = CKEDITOR.replace('articleContent');
    $.get("/articles/${article.id}/content",function (data) {
    	CKEDITOR.instances.articleContent.setData(data);
    })
    $("#saveButton").click(function () {
        //把ckedit的内容放到表单中
        console.info(ckeditor.getData())
        $("#articleContent").html(ckeditor.getData());
        $("#articleSaveForm").ajaxSubmit({
            success:function (data) {
                if(data.success){
                    $.messager.popup("保存成功");
                    $("#content").load("/articles/view");
                }else{
                    $.messager.alert("提示",data.errorMsg);
                }
            }
        })
    });

    //初始化上传文件的插件
    $("#butn").uploadifive({
        buttonText:'上传商品图片',
        fileType: 'image',
        uploadScript:'/uploadImage',
        fileObjName:'img',
        onInit:function(){
            $(".uploadifive-queue").hide();
        },
        onUploadComplete : function(file, data) {
            console.info(data);
            $("img").attr("src",data);
            $("#imgPath").val(data);
        }
    });
})

</script>


